package com.lovely3x.uec.catcher;

import android.content.Context;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;

/**
 * 仅仅记录异常内容的序列化器
 * Created by lovely3x on 16-3-10.
 */
public class ExceptionMessageSerializable extends TextExceptionSerializable {

    @Override
    public boolean serialize(Context context, String dir, String fileName, Throwable throwable) {
        try {
            File recordFile = new File(dir, fileName);
            FileOutputStream fos = new FileOutputStream(recordFile);

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PrintStream ps = new PrintStream(baos);
            throwable.printStackTrace(ps);
            fos.write(baos.toByteArray());
            fos.close();
            return true;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }
}
